<?php
/**
* User模型
* @DateTime 2017-09-05
* @author xyl
*/
class User_model extends MY_Model
{

	private $table='user';

	function __construct()
	{
		parent::__construct();

	}
	/**
	 * 动态获取注册用户列表
	 * @DateTime 2017-09-05
 	 * @author xyl
	 * @param  string $limit [每页显示数量]
	 * @param  string $start [开始位置]
	 * @param  string $info  [信息]
	 * 
	 * @return [array]        [list:数据主体 count:数据总数]
	 */
	public function ajaxGetUserList($limit, $start, $info = false)
	{
		$where['status'] = 1;
		$order = 'create_time desc';
		if(isset($info['name'])){
			$like = array(
				'nickname'	=>	$info['name'],
			);
			$data = $this->hw_getList_like_limit($this->table,$where,'*',$like,$limit,$start);
			if(count($data)>0){
				$total = $this->db->where($where)->like($like,'both')->from($this->table)->count_all_results();
			}else{
				$total = 0;
			}
			return array('data'=>$data,'total'=>$total);
		}
		if(isset($info['start_time']) && !empty($info['start_time'])) $where['create_time >='] = $info['start_time'];
		if(isset($info['end_time']) && !empty($info['end_time'])) $where['create_time <='] = $info['end_time'];

		$data = $this->db->from($this->table)->where($where)->limit($limit,$start)->order_by($order)->get()->result_array();
		if(count($data)>0){
			$total = $this->db->from($this->table)->where($where)->where($where)->count_all_results();
		}else{
			$total = 0;
		}
		return array('data'=>$data,'total'=>$total);
	}
	
	/**
	 * 获取用户信息
	 * @DateTime 2017-09-06
 	 * @author xyl
	 * @param  [type] $where 	查询条件
	 * @return [type]        [description]
	 */
	public function getUser($where)
	{
		$info = $this->hw_getRecord($this->table,$where);
		return $info;
	}

	/**
	 * 改变是否显示排名
	 * @author XYL
	 * @DateTime 2018-06-04
	 * @param    [type]     $post [description]
	 * @return   [type]           [description]
	 */
	public function change_online($post)
	{
		$where = array('id'=>$post['user_id']);
		$update = array(
			'update_time'	=>	date('Y-m-d H:i:s'),
			'is_online'	=>	$post['is_online'],
		);
		$res=  $this->hw_Update($this->table,$update,$where);
		return array(
			'code'	=>	$res?1:0,
			'msg'	=>	$res?'设置成功':'设置失败',
		);
	}
}